{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 读取数据\n",
    "import csv\n",
    "import numpy as np\n",
    "\n",
    "text = open(\"data/HW1/train.csv\", 'r', encoding='big5')\n",
    "rows = csv.reader(text, delimiter=',')\n",
    "data = []\n",
    "a = 0;\n",
    "for r in rows:\n",
    "    if a%18 == 10:\n",
    "        data.append(r)\n",
    "    a = a+1\n",
    "\n",
    "x_data = np.zeros((len(data), 24), dtype = np.int)\n",
    "\n",
    "row = 0\n",
    "for r in data:\n",
    "    for i in range(0, 24):\n",
    "        x_data[row][i] = r[i + 3]\n",
    "    row += 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "n = 9\n",
    "validateDataRow = len(data)\n",
    "X = np.ones((validateDataRow,n + 1), dtype= np.int)\n",
    "Y = np.zeros((validateDataRow), dtype= np.int)\n",
    "\n",
    "for row in range(0, validateDataRow):\n",
    "    for i in range(0, n):\n",
    "        X[row][i] = x_data[row][i]\n",
    "    Y[row] = x_data[row][n]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "#取前n个小时的Pm2.5作为参数\n",
    "n = 9\n",
    "day = 20\n",
    "month = 12\n",
    "validateDataRow = (day*24-n)*month\n",
    "X = np.ones((validateDataRow,n + 1), dtype= np.int)\n",
    "Y = np.zeros((validateDataRow), dtype= np.int)\n",
    "\n",
    "#洗数据\n",
    "for m in range(0, month):\n",
    "    for d in range(0, day):\n",
    "        startHour = 0\n",
    "        dayIndex = m * day + d\n",
    "        if d == 0:\n",
    "            startHour = n\n",
    "        for h in range(startHour, 24):\n",
    "            row = (day*24-n)*m + d * 24 + h - n\n",
    "            for i in range(0, n):\n",
    "                xh = h - n + i\n",
    "                if  xh >= 0: #都是当天的\n",
    "                    X[row][i] = x_data[dayIndex][xh]\n",
    "                else: #取昨天的\n",
    "                    X[row][i] = x_data[dayIndex - 1][xh + 24]\n",
    "            Y[row] = x_data[dayIndex][h]\n",
    "\n",
    "row = 0\n",
    "for x in X:\n",
    "    #print(str(Y[row])+ \" : \"+ str(x))\n",
    "    row += 1\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[-0.07356945  0.08100093  0.16498465 -0.25132885 -0.05843532  0.67978913\n",
      "  -0.66656021 -0.12574716  1.2299787   1.86832964]]\n",
      "L:27.538179110367203\n"
     ]
    }
   ],
   "source": [
    "#求解析解\n",
    "Xt = np.transpose(X)\n",
    "X2 = np.matrix( np.matmul(Xt, X))\n",
    "XtXinv = X2.I\n",
    "XtXinvXt = np.matmul(XtXinv,Xt)\n",
    "W = np.matmul(XtXinvXt,Y)\n",
    "\n",
    "print(W)\n",
    "\n",
    "Yhead = np.matmul(W, np.transpose(X))\n",
    "\n",
    "L = Yhead - Y\n",
    "\n",
    "sum = 0\n",
    "for i in range(0,L.shape[1]):\n",
    "    #print(L[0,i])\n",
    "    sum += L[0,i]*L[0,i]\n",
    "\n",
    "print(\"L:\" + str(sum/L.shape[1]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#递归下降求解\n",
    "itor = 100000\n",
    "lr = 0.00001\n",
    "W = np.zeros((9,1), dtype = np.float)\n",
    "Xt = np.transpose(X)\n",
    "Yt = np.transpose(Y)\n",
    "for i in range(0, itor):\n",
    "    w_grad = 0\n",
    "    Wt = np.transpose(W)\n",
    "    grad = np.matmul(Wt, Xt, X, W) + np.matmul(Yt, Y) + 2 * np.matmul(Wt, Xt, Y)\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[ 33.  60.  16.  33.   5.  41.  46.  25.  38.  26.  31.  59.  41.  45.\n",
      "  23.  18.  51.  30.  19.  20.  16.  31.  44.   4.  63.  48.  26.   1.\n",
      "  21.  48.  31.  15.  21.   4.  14.  39.  15.  28.  12.  54.  47.  20.\n",
      "  59.  17.  54.  51.  62.  37.  54.  42.  39.  29.  43.  21.  30.  43.\n",
      "  17.  19.  39.  27.  10.  25.  27.  66.  52.  24.  49.  54.  25.  39.\n",
      "  68.  43.  51.  12.  13.  25.  66.   4.  43.  36.  13.  34.   7.  24.\n",
      "  10.   7.  15.   6.  16.  19.  42.  11.  14.  17.  38.  11.  19.   6.\n",
      "   9.   5.   7.  17.   6.   8.   5.  37.  31.   0.  20.  20.  21.  14.\n",
      "  10.  27.  13.  13.   4.  40.  34.   0.   2.  12.  16.  21.   6.  27.\n",
      "  28.   9.  23.  25.   0.  34.  11.  17.  25.  27.   6.  26.  71.  53.\n",
      "  21.  19.  27.  11.  12.  17.  11.   4.  17.  10.  43.  21.  18.  13.\n",
      "  11.  13.  20.  38.  10.  28.  47.  17.  70.  14.  35.  31.  17.   6.\n",
      "  63.  24.  18.  70.  14.  11.  18.   0.   9.  18.  25.  20.  43.  34.\n",
      "  27.  17.  11.  54.  32.  27.  12.  32.   9.  14.  37.  76.  26.  16.\n",
      "  62.  19.  23.  27. 170.  16.  67.   4.  74.  48.  12.   7.  63.   7.\n",
      "  40.  84.  14.  99.  47.  91. 106.  88.  29.   7.  29.  65.  35.  27.\n",
      "  43.  13.   8.  69.  32.   0.  35.  11.  14.   4.  14.  20.  20.   0.\n",
      "  18.   3.]\n",
      "33.0:27.31787133674694 L:-5.68212866325306\n",
      "60.0:66.87813155957431 L:6.878131559574314\n",
      "16.0:21.61612761229318 L:5.61612761229318\n",
      "33.0:31.05902855163547 L:-1.9409714483645288\n",
      "5.0:11.300889708472187 L:6.300889708472187\n",
      "41.0:39.69633449472018 L:-1.3036655052798167\n",
      "46.0:42.23706578345667 L:-3.7629342165433286\n",
      "25.0:18.255867069615057 L:-6.744132930384943\n",
      "38.0:52.66073707107765 L:14.660737071077648\n",
      "26.0:34.82594695514236 L:8.825946955142363\n",
      "31.0:40.11643552296813 L:9.116435522968132\n",
      "59.0:60.59578726625128 L:1.5957872662512784\n",
      "41.0:38.57285426079446 L:-2.4271457392055424\n",
      "45.0:45.987154582093105 L:0.9871545820931047\n",
      "23.0:32.0936991764829 L:9.0936991764829\n",
      "18.0:14.401779752263845 L:-3.5982202477361547\n",
      "51.0:55.12034494284842 L:4.120344942848419\n",
      "30.0:24.834278703347653 L:-5.165721296652347\n",
      "19.0:20.828733605028777 L:1.828733605028777\n",
      "20.0:21.348684541737523 L:1.3486845417375228\n",
      "16.0:14.521451725241269 L:-1.4785482747587313\n",
      "31.0:29.63313589958031 L:-1.36686410041969\n",
      "44.0:39.337258661311175 L:-4.662741338688825\n",
      "4.0:11.463610141603287 L:7.4636101416032865\n",
      "63.0:61.00177110325062 L:-1.9982288967493815\n",
      "48.0:46.331690335123824 L:-1.6683096648761762\n",
      "26.0:28.21107368854969 L:2.211073688549689\n",
      "1.0:10.222634838031759 L:9.222634838031759\n",
      "21.0:29.763164911909307 L:8.763164911909307\n",
      "48.0:36.041006032636744 L:-11.958993967363256\n",
      "31.0:20.399099258394873 L:-10.600900741605127\n",
      "15.0:12.10638368945499 L:-2.89361631054501\n",
      "21.0:18.660474663372526 L:-2.3395253366274744\n",
      "4.0:8.513957144483994 L:4.513957144483994\n",
      "14.0:20.372708470075764 L:6.372708470075764\n",
      "39.0:41.083718721018926 L:2.0837187210189256\n",
      "15.0:21.190050465513238 L:6.190050465513238\n",
      "28.0:29.633980484977393 L:1.6339804849773927\n",
      "12.0:7.875718347988959 L:-4.124281652011041\n",
      "54.0:61.62546708294551 L:7.625467082945512\n",
      "47.0:50.295078280417854 L:3.2950782804178544\n",
      "20.0:17.953137894355393 L:-2.046862105644607\n",
      "59.0:53.4914246388575 L:-5.508575361142498\n",
      "17.0:18.847487578636084 L:1.847487578636084\n",
      "54.0:45.866578030074585 L:-8.133421969925415\n",
      "51.0:53.11762793135095 L:2.1176279313509525\n",
      "62.0:63.57674680130262 L:1.576746801302619\n",
      "37.0:43.19350978998314 L:6.193509789983139\n",
      "54.0:54.67093036132962 L:0.6709303613296171\n",
      "42.0:43.73248503951169 L:1.7324850395116869\n",
      "39.0:32.557111374293754 L:-6.442888625706246\n",
      "29.0:26.987041776187027 L:-2.012958223812973\n",
      "43.0:40.27364709002113 L:-2.7263529099788713\n",
      "21.0:26.716063483062335 L:5.716063483062335\n",
      "30.0:41.45391568117207 L:11.45391568117207\n",
      "43.0:41.528708220955124 L:-1.4712917790448756\n",
      "17.0:26.958900492776138 L:9.958900492776138\n",
      "19.0:24.80525860806509 L:5.805258608065088\n",
      "39.0:38.611345123275115 L:-0.3886548767248854\n",
      "27.0:33.68270628957614 L:6.682706289576139\n",
      "10.0:16.581673036264018 L:6.581673036264018\n",
      "25.0:24.53057267792218 L:-0.46942732207782\n",
      "27.0:33.76694802802229 L:6.766948028022291\n",
      "66.0:59.98896229595268 L:-6.011037704047318\n",
      "52.0:51.24073358958027 L:-0.7592664104197269\n",
      "24.0:28.858230286033233 L:4.858230286033233\n",
      "49.0:43.291919429212015 L:-5.708080570787985\n",
      "54.0:56.88678438704064 L:2.8867843870406418\n",
      "25.0:30.595910267301505 L:5.595910267301505\n",
      "39.0:39.463476508971524 L:0.4634765089715245\n",
      "68.0:68.44473460454691 L:0.44473460454690894\n",
      "43.0:55.56704550437428 L:12.567045504374278\n",
      "51.0:47.401645154548504 L:-3.598354845451496\n",
      "12.0:12.074205867272948 L:0.07420586727294776\n",
      "13.0:13.027605189586069 L:0.027605189586068946\n",
      "25.0:38.949887120654225 L:13.949887120654225\n",
      "66.0:65.29852929869615 L:-0.7014707013038475\n",
      "4.0:3.53213741344619 L:-0.4678625865538102\n",
      "43.0:45.51167948149941 L:2.5116794814994066\n",
      "36.0:41.954964269204986 L:5.954964269204986\n",
      "13.0:9.339468270580458 L:-3.6605317294195423\n",
      "34.0:23.549639204222096 L:-10.450360795777904\n",
      "7.0:9.033255286128108 L:2.0332552861281084\n",
      "24.0:33.59569726163664 L:9.595697261636637\n",
      "10.0:12.975786414556838 L:2.975786414556838\n",
      "7.0:7.087317418826853 L:0.08731741882685284\n",
      "15.0:16.38726699115737 L:1.3872669911573716\n",
      "6.0:13.94678744721336 L:7.94678744721336\n",
      "16.0:14.9462247046378 L:-1.0537752953622004\n",
      "19.0:29.098876424397822 L:10.098876424397822\n",
      "42.0:32.18981860971925 L:-9.810181390280754\n",
      "11.0:13.217586995032953 L:2.2175869950329528\n",
      "14.0:15.487655404150722 L:1.487655404150722\n",
      "17.0:7.406552408681767 L:-9.593447591318233\n",
      "38.0:38.448515194330284 L:0.44851519433028386\n",
      "11.0:18.723841722105114 L:7.723841722105114\n",
      "19.0:16.83319230382682 L:-2.16680769617318\n",
      "6.0:10.295573484775115 L:4.295573484775115\n",
      "9.0:11.02011183212684 L:2.0201118321268403\n",
      "5.0:4.411609914218936 L:-0.5883900857810644\n",
      "7.0:13.91218831137618 L:6.91218831137618\n",
      "17.0:20.596826002815 L:3.596826002815\n",
      "6.0:12.528107506553866 L:6.528107506553866\n",
      "8.0:6.974549280674125 L:-1.0254507193258746\n",
      "5.0:14.231934165404878 L:9.231934165404878\n",
      "37.0:39.98280153497472 L:2.982801534974719\n",
      "31.0:30.415963563632577 L:-0.5840364363674233\n",
      "0.0:9.278776610813246 L:9.278776610813246\n",
      "20.0:16.162538898203202 L:-3.837461101796798\n",
      "20.0:15.541518088603851 L:-4.458481911396149\n",
      "21.0:15.988619482121702 L:-5.0113805178782975\n",
      "14.0:19.397240533978383 L:5.397240533978383\n",
      "10.0:13.935464104114336 L:3.9354641041143363\n",
      "27.0:30.11714868145875 L:3.117148681458751\n",
      "13.0:23.84954837589475 L:10.849548375894749\n",
      "13.0:17.258821650082076 L:4.258821650082076\n",
      "4.0:9.265027085892179 L:5.265027085892179\n",
      "40.0:47.665243988088186 L:7.665243988088186\n",
      "34.0:33.08071458059348 L:-0.9192854194065205\n",
      "0.0:1.7335977948945853 L:1.7335977948945853\n",
      "2.0:3.038330731318084 L:1.038330731318084\n",
      "12.0:15.18430464663237 L:3.18430464663237\n",
      "16.0:16.581909327405498 L:0.5819093274054978\n",
      "21.0:16.895970729912342 L:-4.104029270087658\n",
      "6.0:8.191474098236517 L:2.191474098236517\n",
      "27.0:27.63046745437078 L:0.6304674543707804\n",
      "28.0:22.274659504342928 L:-5.725340495657072\n",
      "9.0:14.008275459049774 L:5.008275459049774\n",
      "23.0:22.756909681812445 L:-0.243090318187555\n",
      "25.0:19.066760371465932 L:-5.933239628534068\n",
      "0.0:5.745615048050119 L:5.745615048050119\n",
      "34.0:38.502856483831565 L:4.502856483831565\n",
      "11.0:15.206188609516701 L:4.206188609516701\n",
      "17.0:25.737141250601212 L:8.737141250601212\n",
      "25.0:25.829808009573345 L:0.8298080095733447\n",
      "27.0:21.249966514899953 L:-5.750033485100047\n",
      "6.0:10.082456049405788 L:4.082456049405788\n",
      "26.0:20.716699699882884 L:-5.283300300117116\n",
      "71.0:80.9593203010408 L:9.959320301040805\n",
      "53.0:64.76437024156579 L:11.764370241565786\n",
      "21.0:26.11957564637443 L:5.119575646374429\n",
      "19.0:18.20377386537681 L:-0.7962261346231898\n",
      "27.0:26.783974945210154 L:-0.21602505478984568\n",
      "11.0:9.038242458280253 L:-1.9617575417197468\n",
      "12.0:11.850891142809637 L:-0.14910885719036315\n",
      "17.0:11.23959721169546 L:-5.760402788304541\n",
      "11.0:22.7465920095227 L:11.7465920095227\n",
      "4.0:9.11469516382249 L:5.114695163822489\n",
      "17.0:15.721005165530359 L:-1.278994834469641\n",
      "10.0:18.46795334628908 L:8.467953346289079\n",
      "43.0:53.31744825639137 L:10.317448256391373\n",
      "21.0:25.39618199951748 L:4.396181999517481\n",
      "18.0:26.898518384323086 L:8.898518384323086\n",
      "13.0:17.03040788816352 L:4.03040788816352\n",
      "11.0:14.056579924063904 L:3.0565799240639038\n",
      "13.0:28.870822630123044 L:15.870822630123044\n",
      "20.0:24.469118965551417 L:4.4691189655514165\n",
      "38.0:36.57026304778298 L:-1.42973695221702\n",
      "10.0:3.376923320256596 L:-6.623076679743404\n",
      "28.0:20.77498915748091 L:-7.22501084251909\n",
      "47.0:46.64760433688458 L:-0.3523956631154235\n",
      "17.0:20.96083867082083 L:3.9608386708208307\n",
      "70.0:62.16853392725017 L:-7.8314660727498335\n",
      "14.0:20.560639814773246 L:6.560639814773246\n",
      "35.0:37.21401873438589 L:2.2140187343858884\n",
      "31.0:24.886332943047652 L:-6.113667056952348\n",
      "17.0:24.86407374423564 L:7.86407374423564\n",
      "6.0:0.9902150279220037 L:-5.009784972077997\n",
      "63.0:70.86642252231046 L:7.866422522310458\n",
      "24.0:19.789583229188857 L:-4.210416770811143\n",
      "18.0:18.17529093037184 L:0.1752909303718404\n",
      "70.0:73.36843106377896 L:3.3684310637789565\n",
      "14.0:22.958901150902236 L:8.958901150902236\n",
      "11.0:2.099776700407988 L:-8.900223299592012\n",
      "18.0:26.758413354254714 L:8.758413354254714\n",
      "0.0:2.7232607139194305 L:2.7232607139194305\n",
      "9.0:6.429242781894558 L:-2.5707572181054417\n",
      "18.0:21.37840175358786 L:3.378401753587859\n",
      "25.0:22.782008591148116 L:-2.2179914088518835\n",
      "20.0:24.000301546549693 L:4.000301546549693\n",
      "43.0:45.97859165424542 L:2.9785916542454203\n",
      "34.0:26.612350216039733 L:-7.387649783960267\n",
      "27.0:30.366669601373047 L:3.3666696013730473\n",
      "17.0:12.650622513538913 L:-4.349377486461087\n",
      "11.0:11.120387444425521 L:0.1203874444255213\n",
      "54.0:43.06577532013395 L:-10.934224679866048\n",
      "32.0:39.1639812289925 L:7.163981228992498\n",
      "27.0:34.81990976258674 L:7.8199097625867395\n",
      "12.0:18.15380187226414 L:6.15380187226414\n",
      "32.0:23.683846626276587 L:-8.316153373723413\n",
      "9.0:15.006543708035105 L:6.006543708035105\n",
      "14.0:14.46524521265596 L:0.46524521265595986\n",
      "37.0:35.83375291462667 L:-1.1662470853733282\n",
      "76.0:81.23091667246132 L:5.230916672461319\n",
      "26.0:30.355558812676946 L:4.3555588126769464\n",
      "16.0:12.854837049540588 L:-3.1451629504594116\n",
      "62.0:66.99621756547627 L:4.996217565476272\n",
      "19.0:14.012541777825064 L:-4.987458222174936\n",
      "23.0:21.07578018043374 L:-1.924219819566261\n",
      "27.0:26.51025322665539 L:-0.4897467733446099\n",
      "170.0:130.27981888297654 L:-39.72018111702346\n",
      "16.0:28.538199574977334 L:12.538199574977334\n",
      "67.0:59.86494427086885 L:-7.135055729131153\n",
      "4.0:6.391789562107487 L:2.391789562107487\n",
      "74.0:66.22455735174711 L:-7.775442648252891\n",
      "48.0:38.11289985312539 L:-9.887100146874609\n",
      "12.0:18.38492323442496 L:6.38492323442496\n",
      "7.0:15.10895155649034 L:8.10895155649034\n",
      "63.0:66.3447699076408 L:3.3447699076407957\n",
      "7.0:18.239226881940127 L:11.239226881940127\n",
      "40.0:28.818605648916417 L:-11.181394351083583\n",
      "84.0:77.40895698946741 L:-6.591043010532587\n",
      "14.0:21.407692117336197 L:7.407692117336197\n",
      "99.0:121.40331840124958 L:22.403318401249578\n",
      "47.0:41.08731456494485 L:-5.9126854350551525\n",
      "91.0:86.88486601527052 L:-4.115133984729482\n",
      "106.0:97.45153191776222 L:-8.548468082237775\n",
      "88.0:75.9258052791352 L:-12.074194720864796\n",
      "29.0:27.88367440595335 L:-1.1163255940466499\n",
      "7.0:19.604792683186915 L:12.604792683186915\n",
      "29.0:34.54684769391595 L:5.54684769391595\n",
      "65.0:59.766377969861836 L:-5.233622030138164\n",
      "35.0:30.74173044205678 L:-4.258269557943219\n",
      "27.0:42.742572787570765 L:15.742572787570765\n",
      "43.0:45.02747675477413 L:2.0274767547741277\n",
      "13.0:7.744058065327765 L:-5.255941934672235\n",
      "8.0:6.578378492150396 L:-1.4216215078496042\n",
      "69.0:73.09430472424556 L:4.094304724245561\n",
      "32.0:30.63835444256032 L:-1.3616455574396795\n",
      "0.0:2.5316691627409327 L:2.5316691627409327\n",
      "35.0:43.456959344106544 L:8.456959344106544\n",
      "11.0:17.04335871149378 L:6.043358711493781\n",
      "14.0:23.664158263628714 L:9.664158263628714\n",
      "4.0:11.259956083373833 L:7.259956083373833\n",
      "14.0:11.096358059277115 L:-2.903641940722885\n",
      "20.0:24.23660669972266 L:4.23660669972266\n",
      "20.0:12.901515004516472 L:-7.098484995483528\n",
      "0.0:2.044656056327625 L:2.044656056327625\n",
      "18.0:21.742062740441693 L:3.7420627404416926\n",
      "3.0:1.4203577578002808 L:-1.5796422421997192\n",
      "L^2:5.159952714275129\n"
     ]
    }
   ],
   "source": [
    "# 读取测试数据\n",
    "text = open(\"data/HW1/test.csv\", 'r', encoding='big5')\n",
    "rows = csv.reader(text, delimiter=',')\n",
    "data = []\n",
    "a = 0;\n",
    "for r in rows:\n",
    "    if a%18 == 9:\n",
    "        data.append(r)\n",
    "    a = a+1\n",
    "\n",
    "x_data = np.zeros((len(data), 9), dtype = np.int)\n",
    "\n",
    "row = 0\n",
    "for r in data:\n",
    "    for i in range(0, 9):\n",
    "        x_data[row][i] = r[i + 2]\n",
    "    row += 1\n",
    "    \n",
    "X = np.ones((len(data), 10), dtype = np.int)\n",
    "Y = np.ones(len(data))\n",
    "\n",
    "row = 0  \n",
    "for x in x_data:\n",
    "    for i in range(0, 9):\n",
    "        X[row][i] = x_data[row][i]\n",
    "    #print(x)\n",
    "    #print(str(X[row]) + \":\" + str(Y[row]))\n",
    "    row += 1\n",
    "    \n",
    "#读取结果数据\n",
    "text = open(\"data/HW1/ans.csv\", 'r', encoding='big5')\n",
    "rows = csv.reader(text, delimiter=',')\n",
    "data = []\n",
    "for r in rows:\n",
    "    data.append(r)\n",
    "row = -1\n",
    "for r in data:\n",
    "    if row != -1:\n",
    "        Y[row] = r[1]\n",
    "    row += 1\n",
    "print(Y)\n",
    "Yhead = np.matmul(W, np.transpose(X))\n",
    "\n",
    "L = Yhead - Y\n",
    "\n",
    "sum = 0\n",
    "for i in range(0,L.shape[1]):\n",
    "    print(str(Y[i]) + \":\" + str(Yhead[0,i]) + \" L:\" + str(L[0,i]))\n",
    "    sum += abs(L[0,i])\n",
    "\n",
    "print(\"L^2:\" + str(sum/L.shape[1]))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
